layui.use(['form', 'layer','laydate'], function () {
    var form = layui.form,
        layer = layui.layer,
        laydate = layui.laydate,
        $ = layui.jquery;

    laydate.render({
        elem: '#deliverTime'
    });
    laydate.render({
        elem: '#receiveTime'
    });

    form.on('submit(Add-filter)', function (data) {
        $.ajax({
            url: web.rootPath() + "orderinfo/save",
            type: "post",
            contentType: "application/json",
            data: JSON.stringify(data.field),
            dataType: 'json',
            traditional: true,
            success: function (data) {
                layer.msg("操作成功", {
                    icon: 1,
                    success: function () {
                        reloadTb("Save-frame", "#SearchBtn");
                    }
                });
            },
            error: function (e) {
                layer.msg(e.responseJSON.message, {icon: 2});
            }

        });
        return false;
    });

    form.on('select(customerSelect)',function (data){
        $("linkman").empty()
        $.ajax({
            url: web.rootPath() + "linkman/listByCustomerId?custId="+data.value,
            type: "post",
            contentType: "application/json",
            data: JSON.stringify(data.field),
            dataType: 'json',
            traditional: true,
            success: function (data) {
                console.log(data.data);
                var optionHtml='<option value="">请选择</option>';
                if(data.data.length>0){
                    data.data.forEach(item=>{
                        optionHtml+=`<option value="${item.id}">${item.linkman}</option>`
                    })
                }
                $("#linkman").html(optionHtml);
                form.render('select','component-form-element')
            },
            error: function (e) {
                layer.msg(e.responseJSON.message, {icon: 2});
            }

        });
    });

});
